#!/bin/sh -x

sed 's;dump_dir;'${DUMP_DIR}';g' $SCRIPTS_DIR/information_schema_columns.ctl > $X_TMP_DIR/information_schema_columns_tmp.ctl
sed 's;bad_dir;'${BAD_DIR}';g' $X_TMP_DIR/information_schema_columns_tmp.ctl > $X_TMP_DIR/information_schema_columns.ctl
rm $X_TMP_DIR/information_schema_columns_tmp.ctl

# sed 's;dump_dir;'${DUMP_DIR}';g' $SCRIPTS_DIR/information_schema_columns.ctl > $X_TMP_DIR/information_schema_columns_tmp.ctl
# sed 's;bad_dir;'${BAD_DIR}';g' $X_TMP_DIR/information_schema_columns_tmp.ctl > $X_TMP_DIR/information_schema_columns.ctl
# rm $X_TMP_DIR/information_schema_columns_tmp.ctl

# sed 's;dump_dir;'${DUMP_DIR}';g' $SCRIPTS_DIR/information_schema_key_column_usage.ctl > $X_TMP_DIR/information_schema_key_column_usage_tmp.ctl
# sed 's;bad_dir;'${BAD_DIR}';g' $X_TMP_DIR/information_schema_key_column_usage_tmp.ctl > $X_TMP_DIR/information_schema_key_column_usage.ctl
# rm $X_TMP_DIR/information_schema_key_column_usage_tmp.ctl


mysql $MYSQL_SCHEMA --host=$MYSQL_HOST --user=$MYSQL_UNAME --password=$MYSQL_PASSWD -e "SELECT 
TABLE_CATALOG
,TABLE_SCHEMA
,TABLE_NAME
,COLUMN_NAME
,COLUMN_TYPE
,ORDINAL_POSITION
,IS_NULLABLE
,DATA_TYPE
,CHARACTER_MAXIMUM_LENGTH
,CHARACTER_OCTET_LENGTH
,NUMERIC_PRECISION
,NUMERIC_SCALE
 FROM information_schema.COLUMNS" > $DUMP_DIR/information_schema_columns.txt

sqlldr $REPO_SCHEMA control=$X_TMP_DIR/information_schema_columns.ctl DIRECT=Y SKIP=1 LOG=$LOG_DIR/information_schema_columns.txt.log


# mysql $MYSQL_SCHEMA --host=$MYSQL_HOST --user=$MYSQL_UNAME --password=$MYSQL_PASSWD -e "SELECT 
# CONSTRAINT_CATALOG
# ,CONSTRAINT_SCHEMA
# ,CONSTRAINT_NAME
# ,TABLE_SCHEMA
# ,TABLE_NAME
# ,CONSTRAINT_TYPE
#  FROM information_schema.TABLE_CONSTRAINTS" > $DUMP_DIR/information_schema_table_constraints.txt

# sqlldr $REPO_SCHEMA control=$X_TMP_DIR/information_schema_table_constraints.ctl DIRECT=Y SKIP=1 LOG=$LOG_DIR/information_schema_table_constraints.txt.log

# mysql $MYSQL_SCHEMA --host=$MYSQL_HOST --user=$MYSQL_UNAME --password=$MYSQL_PASSWD -e "SELECT 
# CONSTRAINT_CATALOG
# ,CONSTRAINT_SCHEMA
# ,CONSTRAINT_NAME
# ,TABLE_CATALOG
# ,TABLE_SCHEMA
# ,TABLE_NAME
# ,COLUMN_NAME
# ,ORDINAL_POSITION
# ,POSITION_IN_UNIQUE_CONSTRAINT
# ,REFERENCED_TABLE_SCHEMA
# ,REFERENCED_TABLE_NAME
# ,REFERENCED_COLUMN_NAME
#  FROM information_schema.KEY_COLUMN_USAGE" > $DUMP_DIR/information_schema_key_column_usage.txt


# sqlldr $REPO_SCHEMA control=$X_TMP_DIR/information_schema_key_column_usage.ctl DIRECT=Y SKIP=1 LOG=$LOG_DIR/information_schema_key_column_usage.txt.log